package com.xauto.pioneer.appuser.util;

import android.content.Context;

import com.xauto.pioneer.appuser.http.Constants;
import com.xauto.pioneer.appuser.model.Member;
import com.xauto.pioneer.appuser.model.MemberAuth;

/**公共数据校验类
 * Created by Ellis.Li on 2017/5/3.
 */

public class DataCheckUtil {
    /**
     * 是否登录
     * @param mContext
     * @return
     */
    public static boolean isLogin(Context mContext){
        String memberId = PreferencesUtils.getString(mContext, Constants.KEY_MEMBER_ID);
        String token = PreferencesUtils.getString(mContext, Constants.KEY_TOKEN);
        if (!StringUtils.isBlank(memberId) && !StringUtils.isBlank(token)){
            return true;
        }
        return false;
    }

    /**
     * 获取Member对象
     * @param mContext
     * @return
     */
    public static Member getMemberObj(Context mContext){
        return (Member)SerializeUtil.deSerialization(PreferencesUtils.getString(mContext, Constants.KEY_MEMBER_OBJECT));
    }

    /**
     * 身份是否全部认证通过
     * @param mContext
     * @return
     */
    public static boolean isAuthIdentity(Context mContext){
        Member member = (Member)SerializeUtil.deSerialization(PreferencesUtils.getString(mContext, Constants.KEY_MEMBER_OBJECT));
        if(Integer.parseInt(member.member_auth_info.member_auth_status) == 1 &&Integer.parseInt(member.member_deposit_info.is_deposit)==1){
            return  true;
        }
        return false;
    }

    /**
     * 未完成认证的状态下，获取当前认证到哪一步
     * currentStep:
     * 1：身份证认证状态
     * 2：手持身份证认证状态
     * 3：驾照认证状态
     * 4：银行卡
     * 5：保证金认证状态
     * currentStatus:1-已认证/0-未认证/2-认证中
     * @param context
     * @return
     */
    public  static int[] getCurrentAuthStep(Context context){
        int[] result = new int[2];
       int currentStep = 6;
       int currentStatus = 0;
        Member member = (Member)SerializeUtil.deSerialization(PreferencesUtils.getString(context, Constants.KEY_MEMBER_OBJECT));
        MemberAuth memberAuth = member.member_auth_info;
        int id_number_auth_status = Integer.parseInt(memberAuth.id_number_auth_status);
        int id_number_with_people_auth_status = Integer.parseInt(memberAuth.id_number_with_people_auth_status);
        int driving_license_auth_status = Integer.parseInt(memberAuth.driving_license_auth_status);
        int id_number_bank_status=Integer.parseInt(memberAuth.id_number_bank_status);
        int deposit_auth_status = Integer.parseInt(member.member_deposit_info.is_deposit);
        /*id_number_auth_status != 0*/
        if (id_number_with_people_auth_status != 0 && driving_license_auth_status != 0 && id_number_bank_status != 0&& deposit_auth_status != 0){
            currentStep = 1;
            currentStatus = id_number_auth_status;
        }else if ((id_number_auth_status != 0 && driving_license_auth_status != 0 && id_number_bank_status != 0&& deposit_auth_status != 0)){
            currentStep = 2;
            currentStatus = id_number_with_people_auth_status;
        }else if (id_number_auth_status != 0 && id_number_with_people_auth_status != 0 &&id_number_bank_status != 0&& deposit_auth_status != 0){
            currentStep = 3;
            currentStatus = driving_license_auth_status;
        }else if (id_number_auth_status != 0 && id_number_with_people_auth_status != 0 && driving_license_auth_status != 0&& deposit_auth_status != 0){
            currentStep = 4;
            currentStatus = id_number_bank_status;
        }else if (id_number_auth_status != 0 && id_number_with_people_auth_status != 0 && driving_license_auth_status != 0 && id_number_bank_status != 0){
            currentStep = 5;
            currentStatus = deposit_auth_status;
        }

//        if (Integer.parseInt(memberAuth.id_number_auth_status) != 1){
//            currentStep = 1;
//            currentStatus = Integer.parseInt(memberAuth.id_number_auth_status);
//        }else if (Integer.parseInt(memberAuth.id_number_with_people_auth_status) != 1){
//            currentStep = 2;
//            currentStatus = Integer.parseInt(memberAuth.id_number_with_people_auth_status);
//        }else if (Integer.parseInt(memberAuth.driving_license_auth_status) != 1){
//            currentStep = 3;
//            currentStatus = Integer.parseInt(memberAuth.driving_license_auth_status);
//        }else if (Integer.parseInt(memberAuth.deposit_auth_status) != 1){
//            currentStep = 4;
//            currentStatus = Integer.parseInt(memberAuth.deposit_auth_status);
//        }
        result[0] = currentStep;
        result[1] = currentStatus;
        return result;
    }

    /**
     * 根据当前所在步骤判断当前所在步骤的状态
     * currentStep:
     * 1：身份证认证状态
     * 2：手持身份证认证状态
     * 3：驾照认证状态
     * 4：保证金认证状态
     * currentStatus:1-已认证/0-未认证/2-认证中
     * @param context
     * @return
     */
    public  static int getCurrentStatusOfStep(Context context,int currentStep){

       int currentStatus = 0;
        Member member = (Member)SerializeUtil.deSerialization(PreferencesUtils.getString(context, Constants.KEY_MEMBER_OBJECT));
        MemberAuth memberAuth = member.member_auth_info;
        switch (currentStep){
            case 1:
                currentStatus = Integer.parseInt(memberAuth.id_number_auth_status);
                break;
            case 2:
                currentStatus = Integer.parseInt(memberAuth.id_number_with_people_auth_status);
                break;
            case 3:
                currentStatus = Integer.parseInt(memberAuth.driving_license_auth_status);
                break;
            case 4:
                currentStatus = Integer.parseInt(memberAuth.id_number_bank_status);
                break;
            case 5:
                currentStatus = Integer.parseInt(member.member_deposit_info.is_deposit);
                break;
        }
        return currentStatus;
    }
}
